package com.hyc.myvideo.widget;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.acmenxd.toaster.Toaster;
import com.hyc.myvideo.R;
import com.hyc.utils.StringUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 添加目录
 * Created by dfeads on 2017/7/24.
 */

public class TrainingAddDialog extends Dialog {

  @BindView(R.id.dialog_training_add_catalog) ClearEditText mCatalog;
  @BindView(R.id.dialog_training_add_cancel) TextView mCancel;
  @BindView(R.id.dialog_training_add_confirm) TextView mConfirm;

  private OnTrainingAddListener trainingAddListener;

  public void setTrainingAddListener(OnTrainingAddListener trainingAddListener) {
    this.trainingAddListener = trainingAddListener;
  }

  public TrainingAddDialog(@NonNull Context context) {
    this(context, R.style.myDialogStytle);
  }

  public TrainingAddDialog(@NonNull Context context, @StyleRes int themeResId) {
    super(context, themeResId);
    init(context);
  }

  private void init(Context context) {
    View view = LayoutInflater.from(context).inflate(R.layout.dialog_training_add, null);
    ButterKnife.bind(this, view);
    setContentView(view);
  }

  @OnClick({ R.id.dialog_training_add_cancel, R.id.dialog_training_add_confirm })
  public void onViewClicked(View view) {
    switch (view.getId()) {
      case R.id.dialog_training_add_cancel:
        dismiss();
        break;
      case R.id.dialog_training_add_confirm:
        if (StringUtils.isEmpty(mCatalog.getText().toString().trim())) {
          Toaster.show("目录不能为空");
          return;
        }
        if (trainingAddListener != null) {
          trainingAddListener.getCatalog(mCatalog.getText().toString().trim());
          dismiss();
        }
        break;
    }
    mCatalog.setText("");
  }

  public interface OnTrainingAddListener {
    void getCatalog(String catalog);
  }
}
